package com.cnzz.site1255174697.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cnzz.site1255174697.ConstHost;
import com.cnzz.site1255174697.R;
import com.cnzz.site1255174697.model.KindsTopEntity;
import com.cqyanyu.yanyu.view.XBaseViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 分类顶部
 */
public class KindsTopAdapter extends BaseAdapter {

    private Context context;
    private List<KindsTopEntity> list;

    public KindsTopAdapter(Context context, List<KindsTopEntity> data) {
        this.context = context;
        this.list = data;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public KindsTopEntity getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_kinds_top, null);
        }

        ImageView ivTop = XBaseViewHolder.get(convertView, R.id.iv_top);
        TextView tvTitle = XBaseViewHolder.get(convertView, R.id.tv_title);

        KindsTopEntity kindsTopEntity = list.get(position);
        tvTitle.setText(kindsTopEntity.getName());
        Picasso.with(context).load(ConstHost.IMG_BASE_URL + kindsTopEntity.getIcon()).into(ivTop);
        return convertView;
    }


}
